package shoot.FlyingObject;

import java.awt.Graphics;
import java.awt.image.BufferedImage;


/**
 * @author: dongshipan
 * @date: 2021/7/5 16:41
 * @description:
 */
public class Sky extends BaseFlyingObject {

    private static BufferedImage image;

    static {
        image = readImage("sky.png");
    }

    /**
     * 第二个天空图案的 y
     */
    private int y1;
    /**
     * 速度
     */
    private int step = FlyConstant.SKY_STEP;

    public Sky() {
        super(FlyConstant.WORLD_WIDTH, FlyConstant.WORLD_HEIGHT, 0, 0);
        //第二张图片的坐标
        y1 = -height;
    }

    @Override
    public void step() {
        //System.out.println("天空向下移动");
        y += step;
        y1 += step;
        //如果 y 天空出界将其置于 y1 天空的上方
        if (y >= FlyConstant.WORLD_WIDTH) {
            y = -FlyConstant.WORLD_HEIGHT;
        }
        if (y1 >= FlyConstant.WORLD_HEIGHT) {
            y1 = -FlyConstant.WORLD_WIDTH;
        }
    }

    @Override
    public BufferedImage getImage() {
        return image;
    }

    /**
     * 重写父类中的画图
     */
    @Override
    public void paintObject(Graphics g) {
        g.drawImage(getImage(), x, y, null);
        g.drawImage(getImage(), x, y1, null);
    }
}